import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBZhuanShuYingYongPage/YBMiShuProvider/YBMiShuTongProvider.dart';

import 'YBMiShuTongDetailSubPage.dart';

enum YBMiShuTongDetailType{
  YBMiShuTongDetailType_shangjiku,
  YBMiShuTongDetailType_yiHuoshangji,
}

class YBMiShuTongDetailMainPage extends StatelessWidget {

  final String requestCode;
  final String sysCode;
  final YBMiShuTongDetailType type;
  const YBMiShuTongDetailMainPage({Key key, this.requestCode, this.sysCode,this.type}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    return Container(
      child: Scaffold(
        appBar: AppBar(
          elevation: 0,
          title: Text(YBChineseText.workTaiShangJiDetailTitle),
        ),
        body:MultiProvider(
           providers: [
             ChangeNotifierProvider(create:(context)=>YBMiShuTongShangJiKuDetailProvider()..getMiShuTongShangJuKuDataList(requestCode: requestCode,sysCode: sysCode)),
             ChangeNotifierProvider(create: (context)=> YBMiShuTongShangJiKuDetailQiangDuoShangjiProvider()),
           ],
           child:Consumer<YBMiShuTongShangJiKuDetailProvider>(
               builder: (context,shangDetailModel,child){
                 Widget yiHuoShangJiWidget;
                 Widget xuQiuMiaoShuWidget;
                 Widget yuSuanWidget;
                 Widget hangYeWidget;
                 if (type == YBMiShuTongDetailType.YBMiShuTongDetailType_shangjiku) {
                   yiHuoShangJiWidget = Container(
                     child: Column(
                       mainAxisAlignment: MainAxisAlignment.start,
                       crossAxisAlignment: CrossAxisAlignment.stretch,
                       children: [
                         Container(
                           alignment: Alignment.center,
                           height: YBTextStyle.adapterSize26,
                           color: YBColor.common2D69E0,
                           child: Padding(
                             padding: EdgeInsets.only(left: YBTextStyle.adapterSize20),
                             child: Text('此商机还剩${shangDetailModel.shangJiKuModel.maxGetOrderNumber}次获取机会',
                               style:YBTextStyle.TextStyleA9AEB813,
                             ),
                           ),
                         ),

                         Container(
                           height: YBTextStyle.adapterSize10,
                         ),
                         Container(
                           child: Consumer<YBMiShuTongShangJiKuDetailQiangDuoShangjiProvider>(
                             builder:(context,qiangDuo,child){
                               bool changeStatus = false;
                               if (qiangDuo.shangJiKuQiangDuoStr != null) {
                                  if (qiangDuo.shangJiKuQiangDuoStr == true) {
                                     changeStatus = true;
                                  }
                               }
                               return Container(
                                 height: YBTextStyle.adapterSize44,
                                 child: Padding(
                                   padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                                   child: MaterialButton(
                                       shape: RoundedRectangleBorder(
                                         side: BorderSide.none,
                                         borderRadius: BorderRadius.all(Radius.circular(YBTextStyle.adapterSize8)),
                                       ),
                                       color: YBColor.commonThemeColor,
                                       child: Text(changeStatus?YBChineseText.workTaiYiQiangDuoTitle:YBChineseText.workTaiYiHuoShangJiTitle,style: YBTextStyle.xieGangQingNianTuiGuangYuanBtnText,),
                                       onPressed:changeStatus? null:() async{
                                         qiangDuo.getMiShuTongShangJuKuDataList(sysCode: sysCode,requestCode: requestCode);
                                       }),
                                 ),
                               );
                             }
                           ),
                         ),
                         Container(
                           height: YBTextStyle.adapterSize15,
                         ),
                       ],
                     ),
                   );
                 } else if (type == YBMiShuTongDetailType.YBMiShuTongDetailType_yiHuoshangji) {
                   yiHuoShangJiWidget = Container(

                   );
                 }

                 if (!ObjectUtil.isEmptyString(shangDetailModel.shangJiKuModel.requestServiceDesc)){
                    xuQiuMiaoShuWidget = Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.stretch,
                      children: [
                        Container(
                          color: YBColor.white,
                          child: Padding(
                            padding: EdgeInsets.only(left:YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20,top: YBTextStyle.adapterSize16),
                            child: Text(
                              YBChineseText.workTaiXuQiuMiaoShuTitle,
                              style: YBTextStyle.TextStyle1B1C1F18Medium,
                            ),
                          ),
                        ),
                        Container(
                          color: YBColor.white,
                          child: Padding(
                            padding: EdgeInsets.only(top: YBTextStyle.adapterSize16,bottom: YBTextStyle.adapterSize16,left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                            child: Text(
                              shangDetailModel.shangJiKuModel.requestServiceDesc??"",
                              style: YBTextStyle.TextStyle71747A14,
                            ),
                          ),
                        ),
                      ],
                    );
                 }else{
                   xuQiuMiaoShuWidget = Container();
                 }

                 if (!ObjectUtil.isEmptyString(shangDetailModel.shangJiKuModel.budgetMoneyDesc)){
                   yuSuanWidget = Container(
                     color: YBColor.white,
                     height: YBTextStyle.adapterSize48,
                     child: Padding(
                       padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                       child: Row(
                         mainAxisAlignment: MainAxisAlignment.spaceBetween,
                         crossAxisAlignment: CrossAxisAlignment.center,
                         children: [
                           Container(
                             child: Text(
                               YBChineseText.workTaiYuSuanTitle,
                               style: YBTextStyle.TextStyle1B1C1F18Medium,
                             ),
                           ),
                           Container(
                             child: Text(
                               shangDetailModel.shangJiKuModel.budgetMoneyDesc??"",
                               style: YBTextStyle.TextStyle000000A14,
                             ),
                           ),
                         ],
                       ),
                     ),
                   );
                 }else{
                   yuSuanWidget = Container();
                 }

                 if (!ObjectUtil.isEmptyString(shangDetailModel.shangJiKuModel.userIndustry)){
                   hangYeWidget = Container(
                     height: YBTextStyle.adapterSize48,
                     color: YBColor.white,
                     child: Padding(
                       padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                       child: Row(
                         mainAxisAlignment: MainAxisAlignment.spaceBetween,
                         crossAxisAlignment: CrossAxisAlignment.center,
                         children: [
                           Container(
                             child: Text(
                               YBChineseText.workTaiHangYeTitle,
                               style: YBTextStyle.TextStyle1B1C1F18Medium,
                             ),
                           ),
                           Container(
                             child: Text(
                               shangDetailModel.shangJiKuModel.userIndustry??"",
                               style: YBTextStyle.TextStyle000000A14,
                             ),
                           ),
                         ],
                       ),
                     ),
                   );
                 }else{
                   hangYeWidget = Container();
                 }

                 return Column(
                   children: [
                     Expanded(
                       child: SingleChildScrollView(
                         child: Column(
                           mainAxisAlignment: MainAxisAlignment.start,
                           crossAxisAlignment: CrossAxisAlignment.stretch,
                           children: [
                             Container(
                               child: YBMiShuTongDetailSubPage(requestTagStr:shangDetailModel.shangJiKuModel.requestTag,addressStr:shangDetailModel.shangJiKuModel.address,linkPhone: shangDetailModel.shangJiKuModel.linkPhone,createTime: shangDetailModel.shangJiKuModel.createTime,),
                             ),
                             Container(
                               height: YBTextStyle.adapterSize8,
                             ),
                             xuQiuMiaoShuWidget,
                             Container(
                               height: YBTextStyle.adapterSize8,
                             ),
                             yuSuanWidget,
                             Container(
                               height: YBTextStyle.adapterSize8,
                             ),
                             hangYeWidget,
                           ],
                         ),
                       ),
                     ),
                     Container(
                       child: yiHuoShangJiWidget,
                     ),
                   ],
                 );
               }
           ),
        ),
      ),
    );
  }
}
